package com.jomoim.util;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class SingletonObjectSqlMap 
{
	private static SqlMapClient sqlMapClient;
	
	private SingletonObjectSqlMap() throws Exception
	{
		Reader globalReader = null;
		
		try
		{			
			globalReader = Resources.getResourceAsReader("sqlMap/sqlMapConfig.xml");
			sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(globalReader);
		}
		finally
		{
			if ( globalReader != null)
			{
				globalReader.close();
			}
		}
	}
	
	public static synchronized SqlMapClient getSqlMapInstance() throws Exception
	{
    	if ( sqlMapClient == null ) {
    		new SingletonObjectSqlMap() ;
    	}
		
    	return sqlMapClient;
	}		
}
